home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group99a.txt / 000141_icon-group-sender _Tue Jun 22 12:32:44 1999.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id MAA00996
  4.     for icon-group-addresses; Tue, 22 Jun 1999 12:32:19 -0700 (MST)
  5. Message-Id: <199906221932.MAA00996@baskerville.CS.Arizona.EDU>
  6. Date: Tue, 22 Jun 1999 10:22:34 -0700
  7. From: Steve Wampler <swampler@noao.edu>
  8. X-Accept-Language: en
  9. To: Kostas Oikonomou <oikonomou@att.com>, icon-group@optima.CS.Arizona.EDU
  10. Subject: Re: Assertions in Icon
  11. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  12. Status: RO
  13.  
  14. Kostas Oikonomou wrote:
  15. > Hello,
  16. > Does anyone have a suggestion about how to implement a procedure "assert",
  17. > which, when called with an expression "e" as argument, implements
  18. >                 e | stop("Assertion on line ", &line, " failed!")
  19. > Here &line should be the line on which assert(e) appears.
  20. > Thanks.
  21.  
  22. Hard!
  23.  
  24. As far as I know, there is no easy way to get the line number from
  25. which a procedure was called (too bad, the interpreter must have this
  26. information around or it couldn't generate the traceback messages).
  27. Maybe someone knows of a way to get to this information (I assume it
  28. can be an expensive solution, since the program is going to stop
  29. immediately afterwards)?
  30.  
  31. About the best I can is to have the call pass down the current line
  32. number, as shown in the following example:
  33.  
  34. ----
  35. procedure main()
  36.     assert{3 > 5, &line}
  37. end
  38.  
  39. procedure assert(e)
  40.     if not @e[1] then {
  41.         stop(&errout, "Assertion failed on line ", @e[2] | "unknown")
  42.         }
  43. end
  44. ----
  45.  
  46. Note that the call to assert is really a PDCO (Programmer Defined
  47. Control Operation)
  48. to delay evaluation of the expression until inside the assert procedure.
  49.  
  50.  
  51.  
  52.  
  53. --
  54. Steve Wampler-  SOLIS Project, National Solar Observatory
  55. swampler@noao.edu
  56.